<template>
  <div class="cardStyleModal">
    <a-modal
      :visible.sync="visible"
      v-bind="$attrs"
      v-on="$listeners"
      :maskClosable="false"
      :footer="null"
      width="388px"
      title=""
      wrapClassName="text-style-modal-container"
      @cancel="handleClose()"
    >
      <div class="text-style-modal-body">
        <!-- 标题 -->
        <div class="header">
          <div class="title">卡片颜色设置</div>
          <div class="close-btn" @click="handleClose()"></div>
        </div>
        <!--  -->
        <div class="tip-value">提示：仅支持纯色HEX格式</div>
        <!-- 主体 -->
        <div class="body">
          <!--  -->
          <div class="form-container">
            <a-form-model ref="ruleForm" :model="form" :rules="rules">
              <!-- 边框颜色 -->
              <a-form-model-item
                ref="borderColor"
                label="边框颜色"
                prop="borderColor"
              >
                <div class="icon-form-item">
                  <div class="color-demo-panel">
                    <div class="color-view">
                      <colorPicker
                        v-model="borderColor"
                        label=""
                        size="large"
                        @change="changeTextColor($event, 'borderColor')"
                      ></colorPicker>
                    </div>
                    <div class="color-value">当前色值：{{ borderColor }}</div>
                  </div>
                </div>
              </a-form-model-item>

              <!-- 填充颜色 -->
              <a-form-model-item
                ref="fillColor"
                label="填充颜色"
                prop="fillColor"
              >
                <div class="icon-form-item">
                  <div class="color-demo-panel">
                    <div class="color-view">
                      <colorPicker
                        v-model="fillColor"
                        label=""
                        size="large"
                        @change="changeTextColor($event, 'fillColor')"
                      ></colorPicker>
                    </div>
                    <div class="color-value">当前色值：{{ fillColor }}</div>
                  </div>
                </div>
              </a-form-model-item>

              <!-- 文字颜色 -->
              <a-form-model-item
                ref="textColor"
                label="文字颜色"
                prop="textColor"
              >
                <div class="icon-form-item">
                  <div class="color-demo-panel">
                    <div class="color-view">
                      <colorPicker
                        v-model="textColor"
                        label=""
                        size="large"
                        @change="changeTextColor($event, 'textColor')"
                      ></colorPicker>
                    </div>
                    <div class="color-value">当前色值：{{ textColor }}</div>
                  </div>
                </div>
              </a-form-model-item>

              <!-- 字体边框颜色 -->
              <a-form-model-item
                ref="textBorderColor"
                label="字体边框颜色"
                prop="textBorderColor"
              >
                <div class="icon-form-item">
                  <div class="color-demo-panel">
                    <div class="color-view">
                      <colorPicker
                        v-model="textBorderColor"
                        label=""
                        size="large"
                        @change="changeTextColor($event, 'textBorderColor')"
                      ></colorPicker>
                    </div>
                    <div class="color-value">
                      当前色值：{{ textBorderColor }}
                    </div>
                  </div>
                </div>
              </a-form-model-item>

              <!-- 边框宽度 -->
              <a-form-model-item
                ref="borderWidth"
                label="边框宽度(1或2)"
                prop="borderWidth"
              >
                <a-input
                  type="number"
                  v-model="borderWidthVal"
                  placeholder="请输入边框宽度"
                />
              </a-form-model-item>

              <!-- 背景透明度 -->
              <a-form-model-item
                ref="opacity"
                label="背景透明度(0~1)"
                prop="opacity"
              >
                <a-input
                  type="number"
                  v-model="opacityVal"
                  placeholder="请输入背景透明度"
                />
              </a-form-model-item>
            </a-form-model>
          </div>
          <div class="footer-container">
            <a-button class="cancel" @click="handleClose()">取消</a-button>
            <a-button type="primary" @click="handleSubmit()">保存</a-button>
          </div>
        </div>
      </div>
    </a-modal>
  </div>
</template>
<script>
//[弹窗]卡片样式
import colorPicker from "@/components/TopVUI/color/colorPicker";
export default {
  props: {
    visible: {
      type: Boolean,
      default: false,
    },
    //边框颜色
    borderColor: {
      type: String,
      default: "#F68170",
    },
    //填充颜色
    fillColor: {
      type: String,
      default: "#F68170",
    },
    //文字颜色
    textColor: {
      type: String,
      default: "#F1BD4E",
    },
    //文字边框颜色
    textBorderColor: {
      type: String,
      default: "#2E2001",
    },
    //背景透明度
    opacity: {
      type: Number,
      default: 0.5,
    },
    //边框宽度
    borderWidth: {
      type: Number,
      default: 2,
    },
  },
  components: {
    colorPicker,
  },
  data() {
    return {
      iconFontColor: "",
      form: {},
      rules: {},
      borderWidthVal: 2,
      opacityVal: 0.5,
    };
  },
  watch: {
    borderWidth: {
      handler(val) {
        this.borderWidthVal = val;
      },
    },
    opacity: {
      handler(val) {
        this.opacityVal = val;
      },
    },
  },
  mounted() {},
  methods: {
    //监听颜色改变
    changeTextColor(val, type) {
      this.$emit("update:" + type, val);
    },

    //保存
    handleSubmit() {
      let {
        borderColor,
        fillColor,
        textColor,
        textBorderColor,
        borderWidthVal,
        opacityVal,
      } = this;
      if (Number(borderWidthVal) != 1 && Number(borderWidthVal) != 2) {
        this.$message.warning("边框宽度只能设置1或2");
        return;
      } else if (Number(opacityVal) < 0 || Number(opacityVal) > 1) {
        this.$message.warning("背景透明度应大于0且小于1");
        return;
      }
      this.$emit("change", {
        borderColor,
        fillColor,
        textColor,
        textBorderColor,
        borderWidth: Number(borderWidthVal),
        opacity: Number(opacityVal),
      });
      this.$emit("update:visible", false);
    },
    //关闭
    handleClose() {
      this.$emit("update:visible", false);
    },
  },
};
</script>
<style lang="less" scoped>
/deep/.text-style-modal-container {
  .ant-modal-content {
    border-radius: 0;
    background-color: transparent;
    box-shadow: none;
    .ant-modal-close {
      display: none;
    }
    .ant-modal-body {
      padding: 0 !important;
      .text-style-modal-body {
        // height: 447px;
        background: rgba(1, 30, 38, 0.8);
        display: flex;
        flex-direction: column;
        box-sizing: border-box;
        border: 1px solid rgba(100, 193, 220, 0.6);
        border-radius: 0 8px 0 0;
        .header {
          height: 36px;
          flex-shrink: 0;
          background: linear-gradient(90deg, #00a7d8, rgba(0, 77, 99, 0));
          position: relative;
          &::before {
            content: "";
            display: flex;
            height: 40px;
            width: 300px;
            position: absolute;
            top: 0;
            left: 0;
            background: url("~@/assets/img/portalEntry/modal_icon_1.png");
            background-size: 100% 100%;
          }
          &::after {
            content: "";
            display: flex;
            height: 100%;
            width: 75px;
            position: absolute;
            top: -1px;
            right: -1px;
            background: url("~@/assets/img/portalEntry/modal_icon_2.png");
            background-size: 100% 100%;
          }
          .title {
            position: absolute;
            height: 100%;
            color: #fff;
            font-size: 16px;
            letter-spacing: 1px;
            line-height: 36px;
            padding-left: 12px;
            position: relative;
            &::before {
              content: "";
              position: absolute;
              height: 100%;
              width: 21px;
              background: url("~@/assets/img/portalEntry/modal_icon_3.png");
              background-size: 100% 100%;
              left: -1px;
              top: 0;
            }
          }
          .close-btn {
            position: absolute;
            width: 16px;
            height: 16px;
            background: url("~@/assets/img/portalEntry/modal_icon_4.png")
              no-repeat center center;
            background-size: 12px 12px;
            right: 12px;
            top: 50%;
            transform: translateY(-50%);
            cursor: pointer;
            z-index: 9;
          }
        }
        .tip-value {
          color: #ffe700;
          padding: 10px 0 10px 18px;
        }
        .body {
          flex: 1;
          display: flex;
          flex-direction: column;
          overflow: hidden;
          box-sizing: border-box;
          padding: 0 22px 10px 22px;
          .form-container {
            .ant-form {
              .ant-form-item-label {
                line-height: 20px;
                label {
                  color: #eef9ff;
                }
              }
              .ant-input {
                background: rgba(0, 213, 255, 0.1);
                border: 1px solid #00d5ff;
                color: #eef9ff;
              }

              .color-demo-panel {
                display: flex;
                align-items: center;
                .color-view {
                  width: 104px;
                  height: 32px;
                  background: rgba(0, 213, 255, 0.1);
                  border-radius: 4px;
                  box-sizing: border-box;
                  padding: 8px 12px;
                  position: relative;
                  .fcolorpicker-curbox {
                    width: 80px;
                    height: 16px;
                    border: none;
                    border-radius: 0;
                    position: absolute;
                    top: 50%;
                    left: 50%;
                    transform: translate(-50%, -50%);
                  }
                }
                .color-value {
                  color: #b8f3ff;
                  font-size: 14px;
                  margin-left: 20px;
                }
              }
            }
          }
          .footer-container {
            flex-shrink: 0;
            padding: 30px 0 30px 0;
            display: flex;
            justify-content: center;
            button {
              &:not(:first-child) {
                margin-left: 24px;
              }
              &.cancel {
                background: rgba(0, 213, 255, 0.2);
                border: 1px solid rgba(0, 213, 255, 0.2);
                color: #b8f3ff;
              }
              &.ant-btn-primary {
                color: #fff;
                background: #00d5ff !important;
                border: 1px solid #00d5ff;
              }
            }
          }
        }
      }
    }
  }
}
</style>
